package merge;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MergeDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // 获取配置信息以及封装任务
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        // 设置jar加载路径
        job.setJarByClass(MergeDriver.class);
        // 设置map和reduce类
        job.setMapperClass(MergeMapper.class);
        job.setReducerClass(MergeReduce.class);
        // 设置map输出
        job.setMapOutputKeyClass(MergeBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        // 设置最终输出kv类型
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(MergeBean.class);
        // 设置输入和输出路径
        FileInputFormat.setInputPaths(job, new Path("D:\\input"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\output"));
        // 指定分区器，指定分组比较器，设置reducetask数量
        job.setPartitionerClass(MergePartiner.class);
        job.setNumReduceTasks(1);
        // 提交
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
